<template>
  <div class="app-container">
    <wise-crud
      ref="wise-crud"
      :urls="urls"
      :fields="fields"
      :handle="handle"
      :filters="filters"
    />
  </div>
</template>
<script>
import WiseCrud from '@/components/Crud/wiseCrud'
import { getEntSpaceId } from '@/utils/auth'
export default {
  name: 'FacilityManage',
  components: { WiseCrud },
  data() {
    return {
      urls: {
        list: '/api/v1/welder-sbtx-second/project-equipment-comb/sb_list',
        add: '/api/v1/welder-sbtx-second/project-equipment-comb/create',
        show: '/api/v1/welder-sbtx-second/project-equipment-comb/show/',
        update: '/api/v1/welder-sbtx-second/project-equipment/update/',
        delete: '/api/v1/welder-sbtx-second/project-equipment/remove/'
      }
    }
  },
  computed: {
    spaceId() {
      return this.$store.state.project.spaceId
    },
    entSpaceId() {
      return getEntSpaceId()
    },
    handle() {
      // if (this.$store.state.user.project) {
      //   return ['add']
      // } else {
      //   return ['add', 'filters']
      // }
      return [ ]
    },
    fields() {
      let arr = [{ label: '序号', type: 'index', use: ['table'] }]
      arr.push(
        {
          label: '品牌',
          prop: 'brand',
          type: 'render',
          tableRender: (h, row, index) => {
            return h('div', row.hjEquipmentInfo ? row.hjEquipmentInfo.brand : '')
          },
          viewRender: (h, item, object) => {
            return h('div', object.hjEquipmentInfo ? object.hjEquipmentInfo.brand : '')
          },
          // use: ['table', 'view', 'search']
          use: ['table', 'view']
        },
        {
          label: '焊机种类',
          prop: 'type',
          type: 'render',
          tableRender: (h, row, index) => {
            return h('div', row.hjEquipmentInfo ? row.hjEquipmentInfo.type : '')
          },
          viewRender: (h, item, object) => {
            return h('div', object.hjEquipmentInfo ? object.hjEquipmentInfo.type : '')
          },
          // use: ['table', 'view', 'search']
          use: ['table', 'view']
        },
        {
          label: '设备名称',
          prop: 'name',
          type: 'render',
          tableRender: (h, row, index) => {
            return h('div', row.hjEquipmentInfo ? row.hjEquipmentInfo.name : '')
          },
          viewRender: (h, item, object) => {
            return h('div', object.hjEquipmentInfo ? object.hjEquipmentInfo.name : '')
          },
          use: ['table', 'view']
        },
        {
          label: '设备名称',
          prop: 'equipmentName',
          type: 'select',
          url: '/api/v1/welder-sbtx-second/project-equipment-comb/dropdown-gateway',
          labelKey: 'name',
          valueKey: 'id',
          objKeys: [
            {
              field: 'equipmentId',
              key: 'id'
            }
          ],
          filters: [
            { field: 'st', operator: 'NE', value: 9 },
            {
              field: 'entSpaceId',
              operator: 'EQUALS',
              value: this.entSpaceId
            }
          ],
          rules: [
            { required: true, message: '请选择设备名称', trigger: 'change' }
          ],
          // use: ['add', 'view', 'edit']
          use: ['add', 'edit']
        },
        {
          label: '设备编号',
          prop: 'serialNum',
          type: 'render',
          tableRender: (h, row, index) => {
            return h(
              'div',
              row.hjEquipmentInfo ? row.hjEquipmentInfo.serialNum : ''
            )
          },
          viewRender: (h, item, object) => {
            return h('div', object.equipmentInfo ? object.equipmentInfo.serialNum : '')
          },
          use: ['table', 'view']
        },
        {
          label: '设备型号',
          prop: 'modelNumber',
          type: 'render',
          tableRender: (h, row, index) => {
            return h(
              'div',
              row.hjEquipmentInfo ? row.hjEquipmentInfo.modelNumber : ''
            )
          },
          viewRender: (h, item, object) => {
            return h('div', object.equipmentInfo ? object.equipmentInfo.modelNumber : '')
          },
          use: ['table', 'view']
        },
        {
          label: '设备类型',
          prop: 'typeName',
          type: 'render',
          tableRender: (h, row, index) => {
            return h('div', row.hjEquipmentInfo ? row.hjEquipmentInfo.type : '')
          },
          viewRender: (h, item, object) => {
            return h('div', object.hjEquipmentInfo ? object.hjEquipmentInfo.type : '')
          },
          use: ['table', 'view']
        },
        {
          label: '重量',
          prop: 'weight',
          type: 'render',
          tableRender: (h, row, index) => {
            return h('div', row.typeName ? row.hjEquipmentInfo.weight : '')
          },
          viewRender: (h, item, object) => {
            return h('div', object.typeName ? object.hjEquipmentInfo.weight : '')
          },
          use: ['table', 'view']
        },
        {
          label: '电流',
          prop: 'electricity',
          type: 'render',
          tableRender: (h, row, index) => {
            return h('div', row.typeName ? row.hjEquipmentInfo.electricity : '')
          },
          viewRender: (h, item, object) => {
            return h('div', object.typeName ? object.hjEquipmentInfo.electricity : '')
          },
          use: ['table', 'view']
        },
        {
          prop: 'projectId',
          defaultValue: this.$store.state.project.object.id,
          use: ['add', 'edit']
        },
        {
          prop: 'spaceId',
          defaultValue: this.$store.state.project.spaceId,
          use: ['add', 'edit']
        }
      )
      
      return arr
    },
    filters() {
      return [
        {
          field: 'spaceId',
          operator: 'EQUALS',
          value: this.$store.state.project.spaceId
        }
      ]
    }
  },
  mounted() {
    console.log(this.$store.state.project)
  },
  methods: {}
}
</script>

<style>
</style>
